package site.shihuan.helpdesk.auth.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import site.shihuan.helpdesk.auth.service.DeptService;
import site.shihuan.helpdesk.common.model.RestResult;
import site.shihuan.helpdesk.common.model.RestResultUtils;
import site.shihuan.helpdesk.security.context.UserContext;

/**
 * 部门API
 *
 * @author 周世焕
 * @Date 2021/3/24 20:00
 */
@RestController
@RequestMapping("/v1/auth/dept")
public class DeptController {


    @Autowired
    private DeptService deptService;

    @GetMapping
    public RestResult findDeptByTenant(){
        return RestResultUtils.success(deptService.findByTenant(UserContext.getTenantId()));
    }

    @PostMapping
    public RestResult createDept(@RequestParam String deptName){
        return RestResultUtils.success(deptService.createDept(UserContext.getTenantId(),deptName));
    }

    @PutMapping
    public RestResult updateDept(@RequestParam String deptId, @RequestParam String deptName){
        deptService.updateDept(UserContext.getTenantId(),deptId,deptName);
        return RestResultUtils.success();
    }

    @DeleteMapping("batch")
    public RestResult deleteDept(@RequestParam("deptIds") String[] deptIds){
        deptService.deleteDeptBatch(UserContext.getTenantId(),deptIds);
        return RestResultUtils.success();
    }
}
